//
//  LoginRequestManager.m
//  TrainTree
//
//  Created by wanghui on 2017/8/25.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "LoginRequestManager.h"

@implementation LoginRequestManager
/**获取验证码*/
+ (void)getCodeWithMobile:(NSString *)mobile response:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc] init];
    [param setString:mobile forKey:@"mobile"];
    [param setRequestPath:TrainTreeSendCodeURL];

    [[HttpClient shareInstanceClient] GetReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if ([JSONData[@"c"] integerValue] == 0) {
            responseBlock(JSONData, error, dataTask);
        }else{
               [SVProgressHUD showErrorWithStatus:JSONData[@"m"]];
        }

    }];
}
/**登录*/
+ (void)loginWithMobile:(NSString *)mobile Code:(NSString *)code response:(ResponseData)responseBlock
{
    RequestParam *param = [[RequestParam alloc]init];
    [param setString:mobile forKey:@"mobile"];
    [param setString:code forKey:@"code"];
    [param setRequestPath:TrainTreeLoginURL];

    [[HttpClient shareInstanceClient] PostReqeustParameter:param response:^(id JSONData, NSError *error, NSURLSessionDataTask *dataTask) {
        if (JSONData) {
            if ([JSONData[@"c"] integerValue] == 0) {

                [Session session:JSONData[@"d"]];
                responseBlock(JSONData,error,dataTask);
                [[NSNotificationCenter defaultCenter]postNotificationName:@"reloadUserData" object:nil];
            }else{
                [SVProgressHUD showErrorWithStatus:JSONData[@"m"]];
            }
        }else{

            [SVProgressHUD showErrorWithStatus:@"登录失败，请检查网络"];
        }
    }];
}
@end
